Rust Introduction
官方教程
https://doc.rust-lang.org/stable/book/
民间翻译版: https://kaisery.github.io/trpl-zh-cn/
Why Rust?
from https://kaisery.github.io/trpl-zh-cn/ch00-00-introduction.html
Rust 程序设计语言能帮助你编写更快、更可靠的软件。在编程语言设计中,上层的编程效率和底层的细粒度控制往往不能兼得,而 Rust 则试图挑战这一矛盾。Rust 通过平衡技术能力和开发体验,允许你控制内存使用等底层细节,同时也不需要担心底层控 制带来的各种麻烦。
from https://www.rust-lang.org/
Performance Rust is blazingly fast and memory-efficient: with no runtime or garbage collector, it can power performance-critical services, run on embedded devices, and easily integrate with other languages.
Reliability Rust’s rich type system and ownership model guarantee memory-safety and thread-safety — enabling you to eliminate many classes of bugs at compile-time.
Productivity Rust has great documentation, a friendly compiler with useful error messages, and top-notch tooling — an integrated package manager and build tool, smart multi-editor support with auto-completion and type inspections, an auto-formatter, and more.
安装
https://kaisery.github.io/trpl-zh-cn/ch01-01-installation.html
rustup
Rust 的版本管理命令行工具。
curl --proto '=https' --tlsv1.3 <https://sh.rustup.rs> -sSf | sh
rustc --version
更新
rustup update
快速上手
Hello, World!
// main.rs
fn main() {
println!("Hello, world!");
}
Then,
rustc main.rs
./main
Hello, Cargo!
cargo new hello_cargo // new project
cd hello_cargo
tree
.
├── Cargo.toml
└── src
└── main.rs
cargo build // debug build
cargo build --release // release build
cargo run // run program